package com.mycompany.bigdata;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.goldengate.atg.datasource.AbstractHandler;
import com.goldengate.atg.datasource.DsConfiguration;
import com.goldengate.atg.datasource.DsEvent;
import com.goldengate.atg.datasource.DsOperation;
import com.goldengate.atg.datasource.DsTransaction;
import com.goldengate.atg.datasource.GGDataSource.Status;
import com.goldengate.atg.datasource.meta.DsMetaData;

public class OggHandler extends AbstractHandler { // 繼承它
  private static Logger logger = LoggerFactory.getLogger(OggHandler.class);
  private List<DsOperation> rows = new ArrayList<DsOperation>(); // DsOperation表示一筆增改刪動作

  @Override
  public void init(DsConfiguration arg0, DsMetaData arg1) {
    super.init(arg0, arg1);
    logger.debug("[1]init");
  }

  @Override
  public Status operationAdded(DsEvent e, DsTransaction tx, DsOperation op) {
    logger.debug("[4]operationAdded");
    this.rows.add(op); // 增加一筆record至list
    return Status.OK;
  }

  @Override
  public Status transactionBegin(DsEvent e, DsTransaction tx) {
    logger.debug("[3]transactionBegin");
    return Status.OK;
  }

  @Override
  public Status transactionCommit(DsEvent e, DsTransaction tx) {
    logger.info("[5]transactionCommit size={}", this.rows.size());
    return Status.OK;
  }

  @Override
  public void destroy() {
    logger.debug("[7]destory");
  }

  @Override
  public Status metaDataChanged(DsEvent e, DsMetaData meta) {
    logger.debug("[2]metaDataChanged");
    return Status.OK;
  }

  @Override
  public String reportStatus() {
    logger.debug("destory[6]");
    return "status report...";
  }
}